package com.hdoit.kylin.web.money.providers;

import java.util.ArrayList;
import java.util.List;
import com.hdoit.kylin.logical.baseInfo.model.MoneyType;
import com.hdoit.kylin.logical.baseInfo.service.IMoneyTypeService;
import com.hdoit.kylin.logical.user.service.IStudentService;
import com.hdoit.kylin.logical.user.service.ITeacherService;
import com.hdoit.kylin.web.common.CommonWebUtils;
import com.tennetcn.common.aop.CommonApplicationContextUtil;
import com.tennetcn.common.message.ListItem;
import com.tennetcn.common.message.LoginModel;
import com.tennetcn.component.attribute.provider.ISingleOptionListProvider;
import com.tennetcn.component.web.SessionWebFactory;
import com.tennetcn.web.cbase.providers.base.DataListProviderBase;

/** 
 * @author      chenghuan
 * @email       79763939@qq.com
 * @createtime  2017年5月17日 上午9:17:39
 * @comment 
 */
public class MoneyTypeOwnProvider extends  DataListProviderBase implements ISingleOptionListProvider<ListItem>{
	
	@Override
	public List<ListItem> getDataList(Object viewData) {
		List<MoneyType> moneyTypes= getOwnProjectList();
		if(moneyTypes==null||moneyTypes.size()<=0){
			return null;
		}
		dataList=new ArrayList<ListItem>();
		ListItem listItem=null;
		for (MoneyType moneyType : moneyTypes) {
			listItem=new ListItem();
			listItem.setText(moneyType.getMoneyType());
			listItem.setValue(moneyType.getId());
			dataList.add(listItem);
		}
		return dataList;
	}

	
	
	private List<MoneyType> getOwnProjectList(){
		SessionWebFactory sessionWebFactory=CommonApplicationContextUtil.getCurrentContext().getBean(SessionWebFactory.class);
		IMoneyTypeService moneyTypeService=CommonApplicationContextUtil.getCurrentContext().getBean(IMoneyTypeService.class);
		LoginModel loginModel=sessionWebFactory.getCurrentLogin();
		String groupId = null;
		if(CommonWebUtils.isTeacher(loginModel)){
			ITeacherService teacherService=CommonApplicationContextUtil.getCurrentContext().getBean(ITeacherService.class);
    		groupId=teacherService.queryGroupIdByLoginId(loginModel.getLoginId());
    		return moneyTypeService.queryListByOwn(groupId);
    	}else if(CommonWebUtils.isStudent(loginModel)){
    		IStudentService studentService=CommonApplicationContextUtil.getCurrentContext().getBean(IStudentService.class);
    		groupId=studentService.queryGroupIdByLoginId(loginModel.getLoginId());
    		return moneyTypeService.queryListByOwn(groupId);
    	}
    	return moneyTypeService.queryList();
	}

}
